package com.kaiwukj.android.ufamily.mvp.helper;

import com.blankj.utilcode.util.SPUtils;

public class TokenStore {
    private static final String SP = "app_auth";
    private static final String TOKEN = "token";
    private static final String TOKEN_DEFAULT = "Basic anlsOmp5bA==";

    public static synchronized void setToken(String token, String tokenType) {
        SPUtils.getInstance(SP).put(TOKEN, String.format("%s %s", tokenType, token));
    }

    public static void setToken(String token) {
        setToken(token, "bearer");
    }

    public static synchronized String getToken() {
        return SPUtils.getInstance(SP).getString(TOKEN, TOKEN_DEFAULT);
    }

    public static synchronized boolean isLogin() {
        return !getToken().startsWith("Basic");
    }

    public static void clear() {
        SPUtils.getInstance(SP).clear();
    }
}
